<template>
  <div style="width: 100%; height: auto; background: #f7f8fa;padding: 1px 0">
    <div class="steps">
      <el-steps direction="horizontal" :active="active" :align-center="true" style="height: auto width: 100%">
        <el-step title="绑定小程序"></el-step>
        <el-step title="发布小程序"></el-step>
        <el-step title="设置微信支付"></el-step>
      </el-steps>
    </div>
    <appletCategory ref="mychild" v-if="active == 1 && authorizationStatus == 0" @Next="Next" :nextStep="nextStep">
    </appletCategory>
    <div class="bg" v-if="active == 1 && authorizationStatus != 0">
      <div class="AppletsBind">
        <div class="AppletsBindP">将店铺绑定微信小程序，享微信9亿用户流量</div>
        <div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivLeft">
              <div class="AppletsBindDivLeftImg"></div>
              <el-button class="AppletsBindButton" type="primary" @click="authorization">已有小程序，立即绑定</el-button>
              <div class="AppletsBindTitle" style="color: #9797a1; font-size: 12px">
                <div style="width: 200px; text-align: center">
                  为保证所有功能的正常使用，<br />请把所有权限统一授权给文嘟嘟
                </div>
              </div>
            </div>
          </div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivRight">
              <div class="AppletsBindDivRightImg"></div>
              <el-button class="AppletsBindButton" @click="register">没有小程序，立即申请</el-button>
              <div class="AppletsBindTitle" style="color: #9797a1; font-size: 12px">
                <div style="width: 200px; text-align: center">
                  请在微信公众平台申请新的小程序，<br />申请成功后再绑定文嘟嘟
                </div>
              </div>
            </div>
          </div>
        </div>

        <el-button class="AppletsBindbtn" @click="Next" :disabled="nextStep"><span
            class="AppletsBindbtnIcon"></span><span>下一步</span></el-button>
      </div>
    </div>
    <div class="bg" v-if="active == 2">
      <div class="AppletsBind">
        <div class="AppletsBindP">发布小程序</div>
        <div>
          <div class="AppletsBindDiv3">
            <div :class="auditstatus != 1 ? 'AppletsBindDivRelease':'erroeAppletsBindDivRelease' ">
              <div class="AppletsBindDivReleaseImg"></div>
              <div>
                <div class="AppletsBindBox" v-if="auditstatus == 0">
                  <div v-if="releaseType == 'true' || releaseType == true ">
                    <div v-if= "funcTypeStatus == 'true' || funcTypeStatus == true " >
                      <el-button v-model="releaseType" disabled
                                 style="width:186px;margin: 30px 0 15px 0;color:color:#9797A1;">审核成功
                      </el-button>
                      <el-button class="AppletsBindButton2" disabled type="primary" @click="submitAuditcilck">已自动发布小程序
                      </el-button>
                    </div>
                    <div v-if= "funcTypeStatus == 'false' || funcTypeStatus == null || funcTypeStatus == false " >
                      <el-button v-model="releaseType" disabled
                                 style="width:186px;margin: 30px 0 15px 0;color:color:#9797A1;">审核成功
                      </el-button>
                      <el-checkbox  v-model="funcType" label="审核直播权限" border
                                   style="width:186px;margin: 0px 0 15px 0;color:color:#9797A1;"></el-checkbox>
                      <el-button class="AppletsBindButton2" type="primary" @click="submitAuditcilck">重新提交审核</el-button>
                    </div>
                  </div>
                  <div v-if="releaseType == 'false' || releaseType == false ">
                    <div v-if="releaseStatus == false">
                      <el-button disabled style="width:186px;margin: 30px 0 15px 0;color:color:#9797A1;">审核通过请发布
                      </el-button>
                      <el-button class="AppletsBindButton2" type="primary"  @click="release">发布小程序</el-button>
                    </div>

                    <div v-if="releaseStatus == true">
                      <el-button disabled style="width:186px;margin: 30px 0 15px 0;color:color:#9797A1;">已发布
                      </el-button>
                    </div>

                  </div>
                </div>
                <div class="AppletsBindBox" v-else-if="auditstatus == 1">

                  <el-popover placement="top-start" width="100%" trigger="click">
                    <div v-html="reason" style="font-size: 12px; color: #666;text-align: left;line-height: 26px;"></div>
                    <el-button slot="reference" style="width:186px;margin: 30px 0 15px 0;color:color:#9797A1;">审核失败查看原因
                    </el-button>
                  </el-popover>
                  <el-checkbox v-model="releaseType" label="审核通过自动发布" border
                               style="width:186px;margin: 0px 0 15px 0;color:color:#9797A1;"></el-checkbox>
                  <el-checkbox v-model="funcType" label="审核直播权限" border
                               style="width:186px;margin: 0px 0 15px 0;color:color:#9797A1;"></el-checkbox>

                  <el-button class="AppletsBindButton2" type="primary" @click="submitAuditcilck">重新提交审核</el-button>
                </div>
                <div class="AppletsBindBox" v-else-if="auditstatus == 2">
                  <el-button disabled style="width:186px;margin: 30px 0 15px 0;color:color:#9797A1;">正在审核中...
                  </el-button>
                  <el-button class="AppletsBindButton2" disabled type="primary" @click="submitAuditcilck">请耐心等待
                  </el-button>
                </div>
                <div class="AppletsBindBox" v-else-if="auditstatus == 3">
                  <el-checkbox v-model="releaseType" label="审核通过自动发布" border
                    style="width:186px;margin: 30px 0 15px 0;color:color:#9797A1;"></el-checkbox>
                  <el-checkbox v-model="funcType" label="审核直播权限" border
                    style="width:186px;margin: 0px 0 15px 0;color:color:#9797A1;"></el-checkbox>
                  <el-button class="AppletsBindButton2" type="primary" @click="submitAuditcilck">提交审核</el-button>
                </div>
                <div class="AppletsBindBox" v-else>
                  <el-checkbox v-model="releaseType" label="审核通过自动发布" border
                    style="width:186px;margin: 30px 0 15px 0;color:color:#9797A1;"></el-checkbox>
                  <el-checkbox v-model="funcType" label="审核直播权限" border
                    style="width:186px;margin: 0px 0 15px 0;color:color:#9797A1;"></el-checkbox>
                  <el-button class="AppletsBindButton2" type="primary" @click="submitAuditcilck">提交审核</el-button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div style="display: flex" class="AppletsBindbtnS">
          <el-button class="AppletsBindbtn1" @click="Next3"><span class="AppletsBindbtnIcon"></span><span>上一步</span>
          </el-button>
          <el-button class="AppletsBindbtn2" @click="Next4"><span class="AppletsBindbtnIcon"></span><span>下一步</span>
          </el-button>
        </div>
      </div>
    </div>
    <div class="bg" v-if="active == 3">
      <div class="AppletsBind" v-if="active == 3">
        <div class="AppletsBindP">设置微信支付</div>


        <!-- 已设置支付方式  -->
        <div v-if="auditState == 'APPLYMENT_STATE_FINISHED' " style="display: flex; justify-content: center">

          <div class="AppletsBindDiv" v-if="false">
            <div class="AppletsBindDivLeft">
              <div class="AppletsBindDivtopImg">
                <img :src="sign_url" />
              </div>
              <div class="AppletsBindBox">
                <el-popover placement="top-start" width="100%" trigger="click">
                  <div style="
                    color: #9797a1;
                    height: 100%;
                    font-size: 12px;
                  ">
                    <div style="text-align: left;line-height:26px;" v-if="audit_detail">
                      <div v-for="(item, index) in audit_detail" :key="index" style="word-wrap: break-word">
                        {{ index + 1 }}.{{ item.reject_reason }}
                      </div>
                    </div>
                    <div style="text-align: left;line-height:26px;" v-if="applyment_state_msg">
                      {{ applyment_state_msg }}
                    </div>
                  </div>
                  <el-button slot="reference"
                    style="width:186px;color:color:#9797A1;position: relative;left: -57px;top: -20px;">
                    入驻成功，扫码查看结果
                  </el-button>

                </el-popover>
                <el-button style="position: relative;bottom: 5px;left: -57px;width: 186px;height: 40px;"
                  class="AppletsBindButton2" type="primary" @click="getWechatPayAuditList">
                  切换支付方式</el-button>
              </div>
            </div>
          </div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivRight">
              <div class="GainCommercial"></div>
              <div style="
                  font-size: 12px;
                  color: #9797a1;
                  position: relative;
                  top: 15px;
                  width: 195px;
                  text-align: center;
                  left: -65px;
                ">
                请联系商户代表获取商户ID
              </div>
              <el-input class="AppletsBindButton" v-model="MerchantID"
                style="width: 195px; margin-bottom: 15px; top: 25px"></el-input>
              <el-button class="AppletsBindButton" @click="setPaymentTypeclick" style="top: 25px">保存</el-button>
            </div>
          </div>
        </div>


        <!-- 审核中 -->
        <div v-if="auditState == 'APPLYMENT_STATE_AUDITING'">
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivLeft">
              <div class="AppletsBindDivtopImg">
                <img :src="sign_url" />
              </div>
              <div class="AppletsBindBox">
                <el-popover placement="top-start" width="100%" trigger="click">
                  <div style="
                    color: #9797a1;
                    height: 100%;
                    font-size: 12px;
                  ">
                    <div style="text-align: left;line-height:26px;" v-if="audit_detail">
                      <div v-for="(item, index) in audit_detail" :key="index" style="word-wrap: break-word">
                        {{ index + 1 }}.{{ item.reject_reason }}
                      </div>
                    </div>
                    <div style="text-align: left;line-height:26px;" v-if="applyment_state_msg">
                      {{ applyment_state_msg }}
                    </div>
                  </div>
                  <el-button slot="reference"
                    style="width:186px;color:color:#9797A1;position: relative;left: -57px;top: -20px;">查看审核结果
                  </el-button>
                </el-popover>
                <!--                <el-button style="-->
                <!--                    position: relative;-->
                <!--                    bottom: 5px;-->
                <!--                    left: -57px;-->
                <!--                    width: 186px;-->
                <!--                    height: 40px;-->
                <!--                  " class="AppletsBindButton2" type="primary" @click="registerPlay">设置支付方式-->
                <!--                </el-button>-->
              </div>
            </div>
          </div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivRight">
              <div class="GainCommercial"></div>
              <div style="
                  font-size: 12px;
                  color: #9797a1;
                  position: relative;
                  top: 15px;
                  width: 195px;
                  text-align: center;
                  left: -65px;
                ">
                请联系商户代表获取商户ID
              </div>
              <el-input class="AppletsBindButton" v-model="MerchantID"
                style="width: 195px; margin-bottom: 15px; top: 25px"></el-input>
              <el-button class="AppletsBindButton" @click="setPaymentTypeclick" style="top: 25px">保存</el-button>
            </div>
          </div>
        </div>

        <!-- 申请单已被撤销 -->
        <div v-if="auditState == 'APPLYMENT_STATE_CANCELED'">
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivLeft">
              <div class="AppletsBindDivtopImg">
                <img :src="sign_url" />
              </div>
              <div class="AppletsBindBox">
                <el-popover placement="top-start" width="100%" trigger="click">
                  <div style="
                    color: #9797a1;
                    height: 100%;
                    font-size: 12px;
                  ">
                    <div style="text-align: left;line-height:26px;" v-if="audit_detail">
                      <div v-for="(item, index) in audit_detail" :key="index" style="word-wrap: break-word">
                        {{ index + 1 }}.{{ item.reject_reason }}
                      </div>
                    </div>
                    <div style="text-align: left;line-height:26px;" v-if="applyment_state_msg">
                      {{ applyment_state_msg }}
                    </div>
                  </div>
                  <el-button slot="reference"
                    style="width:186px;color:color:#9797A1;position: relative;left: -57px;top: -20px;">查看审核结果
                  </el-button>
                </el-popover>
                <el-button style="
                    position: relative;
                    bottom: 5px;
                    left: -57px;
                    width: 186px;
                    height: 40px;
                  " class="AppletsBindButton2" type="primary" @click="registerPlay">修改申请单
                </el-button>
              </div>
            </div>
          </div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivRight">
              <div class="GainCommercial"></div>
              <div style="
                  font-size: 12px;
                  color: #9797a1;
                  position: relative;
                  top: 15px;
                  width: 195px;
                  text-align: center;
                  left: -65px;
                ">
                请联系商户代表获取商户ID
              </div>
              <el-input class="AppletsBindButton" v-model="MerchantID"
                style="width: 195px; margin-bottom: 15px; top: 25px"></el-input>
              <el-button class="AppletsBindButton" @click="setPaymentTypeclick" style="top: 25px">保存</el-button>
            </div>
          </div>
        </div>

        <!--  已驳回-->
        <div v-if="auditState == 'APPLYMENT_STATE_REJECTED'">
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivLeft">
              <div class="AppletsBindDivtopImg">
                <img :src="sign_url" />
              </div>
              <div class="AppletsBindBox">
                <el-popover placement="top-start" width="100%" trigger="click">
                  <div style="
                    color: #9797a1;
                    height: 100%;
                    font-size: 12px;
                  ">
                    <div style="text-align: left;line-height:26px;" v-if="audit_detail">
                      <div v-for="(item, index) in audit_detail" :key="index" style="word-wrap: break-word">
                        {{ index + 1 }}.{{ item.reject_reason }}
                      </div>
                    </div>
                    <div style="text-align: left;line-height:26px;" v-if="applyment_state_msg">
                      {{ applyment_state_msg }}
                    </div>
                  </div>
                  <el-button slot="reference"
                    style="width:186px;color:color:#9797A1;position: relative;left: -57px;top: -20px;">查看审核结果
                  </el-button>
                </el-popover>
                <el-button style="
                    position: relative;
                    bottom: 5px;
                    left: -57px;
                    width: 186px;
                    height: 40px;
                  " class="AppletsBindButton2" type="primary" @click="registerPlay">修改申请单
                </el-button>
              </div>
            </div>
          </div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivRight">
              <div class="GainCommercial"></div>
              <div style="
                  font-size: 12px;
                  color: #9797a1;
                  position: relative;
                  top: 15px;
                  width: 195px;
                  text-align: center;
                  left: -65px;
                ">
                请联系商户代表获取商户ID
              </div>
              <el-input class="AppletsBindButton" v-model="MerchantID"
                style="width: 195px; margin-bottom: 15px; top: 25px"></el-input>
              <el-button class="AppletsBindButton" @click="setPaymentTypeclick" style="top: 25px">保存</el-button>
            </div>
          </div>
        </div>

        <!--   已创建申请单     -->
        <div v-if="auditState == 1">
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivLeft">
              <div class="AppletsBindDivtopImg">
                <!--                <img :src="sign_url"/>-->
              </div>
              <div class="AppletsBindBox">
                <el-popover placement="top-start" width="100%" trigger="click">
                  <div style="
                    color: #9797a1;
                    height: 100%;
                    font-size: 12px;
                  ">
                    <div style="text-align: left;line-height:26px;" v-if="audit_detail">
                      <div v-for="(item, index) in audit_detail" :key="index" style="word-wrap: break-word">
                        {{ index + 1 }}.{{ item.reject_reason }}
                      </div>
                    </div>
                    <div style="text-align: left;line-height:26px;" v-if="applyment_state_msg">
                      {{ applyment_state_msg }}
                    </div>
                  </div>
                  <!--                  <el-button slot="reference"-->
                  <!--                             style="width:186px;color:color:#9797A1;position: relative;left: -57px;top: -20px;">查看审核结果-->
                  <!--                  </el-button>-->
                </el-popover>

                <el-button slot="reference"
                  style="width:186px;color:color:#9797A1;position: relative;left: -57px;top: -20px;"
                  @click="getWechatPayAuditList">
                  选择已有支付方式</el-button>

                <el-button style="
                    position: relative;
                    bottom: 5px;
                    left: -57px;
                    width: 186px;
                    height: 40px;
                  " class="AppletsBindButton2" type="primary" @click="registerPlay">继续填写
                </el-button>


              </div>
            </div>
          </div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivRight">
              <div class="GainCommercial"></div>
              <div style="
                  font-size: 12px;
                  color: #9797a1;
                  position: relative;
                  top: 15px;
                  width: 195px;
                  text-align: center;
                  left: -65px;
                ">
                请联系商户代表获取商户ID
              </div>
              <el-input class="AppletsBindButton" v-model="MerchantID"
                style="width: 195px; margin-bottom: 15px; top: 25px"></el-input>
              <el-button class="AppletsBindButton" @click="setPaymentTypeclick" style="top: 25px">保存</el-button>
            </div>
          </div>
        </div>


        <!-- 未添加申请 -->
        <div v-if="auditState == 0">
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivLeft">
              <div class="AppletsBindDivtopImg">
                <!--                <img :src="sign_url"/>-->
              </div>
              <div class="AppletsBindBox">
                <el-button slot="reference"
                  style="width:186px;color:color:#9797A1;position: relative;left: -57px;top: -20px;"
                  @click="getWechatPayAuditList">
                  选择已有支付方式</el-button>
                <el-button style="  position: relative; bottom: 5px; left: -57px;width: 186px;height: 40px;  "
                  class="AppletsBindButton2" type="primary" @click="registerPlay">
                  立即填写申请资料</el-button>
              </div>
            </div>
          </div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivRight">
              <div class="GainCommercial"></div>
              <div style="
                  font-size: 12px;
                  color: #9797a1;
                  position: relative;
                  top: 15px;
                  width: 195px;
                  text-align: center;
                  left: -65px;
                ">
                请联系商户代表获取商户ID
              </div>
              <el-input class="AppletsBindButton" v-model="MerchantID"
                style="width: 195px; margin-bottom: 15px; top: 25px"></el-input>
              <el-button class="AppletsBindButton" @click="setPaymentTypeclick" style="top: 25px">保存</el-button>
            </div>
          </div>
        </div>

        <!--待签约 -->
        <div v-if="auditState == 'APPLYMENT_STATE_TO_BE_SIGNED'">
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivLeft">
              <div class="AppletsBindDivtopImg">
                <img :src="sign_url" />
              </div>
              <div class="AppletsBindBox">
                <el-popover placement="top-start" width="100%" trigger="click">
                  <div style="
                    color: #9797a1;
                    height: 100%;
                    font-size: 12px;
                  ">
                    <div style="text-align: left;line-height:26px;" v-if="audit_detail">
                      <div v-for="(item, index) in audit_detail" :key="index" style="word-wrap: break-word">
                        {{ index + 1 }}.{{ item.reject_reason }}
                      </div>
                    </div>
                    <div style="text-align: left;line-height:26px;" v-if="applyment_state_msg">
                      {{ applyment_state_msg }}
                    </div>
                  </div>
                  <el-button slot="reference"
                    style="width:186px;color:color:#9797A1;position: relative;left: -57px;top: -20px;">请扫码完成签约
                  </el-button>
                </el-popover>
              </div>
            </div>
          </div>
          <div class="AppletsBindDiv">
            <div class="AppletsBindDivRight">
              <div class="GainCommercial"></div>
              <div style="
                  font-size: 12px;
                  color: #9797a1;
                  position: relative;
                  top: 15px;
                  width: 195px;
                  text-align: center;
                  left: -65px;
                ">
                请联系商户代表获取商户ID
              </div>
              <el-input class="AppletsBindButton" v-model="MerchantID"
                style="width: 195px; margin-bottom: 15px; top: 25px"></el-input>
              <el-button class="AppletsBindButton" @click="setPaymentTypeclick" style="top: 25px">保存</el-button>
            </div>
          </div>
        </div>


        <div style="display: flex">
          <el-button class="AppletsBindbtn1" @click="Next1"><span class="AppletsBindbtnIcon"></span><span>上一步</span>
          </el-button>
          <el-button class="AppletsBindbtn2" type="primary" @click="complete"><span
              class="AppletsBindbtnIcon"></span><span>完成</span></el-button>
        </div>
      </div>

      <el-dialog title="选择已有支付方式" :visible.sync="dialogVisible" width="50%" height="50%">
                <div style="margin-left: 85%">
                  <el-button type="success" @click="newRegisterPlay" plain>新增支付授权</el-button>
                </div>

        <div style="margin-top: 10px">
          <el-table :data="payData">
            <el-table-column property="businessCode" label="申请单号" width="200"></el-table-column>
            <el-table-column property="merchantName" label="商户姓名" width="200"></el-table-column>
            <el-table-column property="auditState" label="授权状态"></el-table-column>
            <el-table-column property="subMchid" label="商户号"></el-table-column>
            <el-table-column property="sceneStr" label="适用范围"></el-table-column>
            <el-table-column property="createTime" label="申请时间"></el-table-column>
            <el-table-column fixed="right" label="操作" width="100">
              <template slot-scope="scope">
                <el-button v-if="scope.row.select == 1 && scope.row.subMchid != MerchantID" size="mini" type="text"
                  @click="switchPay(scope.row)" icon="el-icon-edit" v-hasPermi="['supplier:info:edit']">选择
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

      </el-dialog>
    </div>
  </div>
</template>
<script>
  import {
    appletGrant,
    getAuditstatusRequest,
    submitAuditRequest,
    releaseRequest,
    setPaymentTypeRequest,
    isBindThirdParty,
  } from "@/api/applet/authorization";
  import {
    getCommercialData,
    wechatPayAuditList,
    switchPayAudit
  } from "@/api/applet/payAudit";

  import {
    applyFor
  } from "@/api/applet/broadcast";

  import appletCategory from "../appletCategory/index.vue";

  export default {
    components: {
      appletCategory
    },
    data() {
      return {
        //弹框
        dialogVisible: false,
        //已完成授权支付方式
        payData: [],
        //小程序AppID
        authorizerAppid: '',
        //绑定授权单
        businessCode: '',
        //是否发布
        isIssueStatus:'',
        MerchantIDType: null,
        nextStep: true,
        nextStep1: true,
        nextStep2: true,
        releaseType: false,
        funcType: false,
        funcTypeStatus: false,
        releaseStatus:false,
        active: 1,
        MerchantID: null,
        auditstatus: null,
        authorizationType: "applet",
        authorizationStatus: null,
        auditState: "",
        reason: "",
        applet: "",
        mpInfo: "",
        sign_url: "",
        applyment_state_msg: "",
        reject_reason: "",
        audit_detail: "",
        CommercialData: null,

        QuerySwitchPayAuditVo: {
          authorizerAppid: '',
          //授权单号
          businessCode: '',
          //商户号
          subMchid: '',
          //授权方类型(小程序：applet，公众号：allwork)',
          authorizerType: ''
        }
      };
    },
    created() {
      this.getisBindThirdParty();
      var msg = location.search.split("?")[1];
      if (msg != null && msg != "") {
        let status = msg.indexOf("=");
        console.log(status);
        let statusMsg = location.search.split("=")[1];
        let decode = decodeURI(statusMsg);
        if ("success" == status) {
          this.authorizationSuccess(decode);
        } else {
          this.authorizationError(decode);
        }
      }
    },
    methods: {
      authorizationSuccess() {
        this.$message({
          message: "授权成功",
          type: "success",
        });
      },
      authorizationError(decode) {
        this.$message({
          message: decode,
          type: "warning",
        });
      },
      getCommercial(businessCode) {
        getCommercialData(businessCode).then((response) => {
          this.CommercialData = response.data;
          this.auditState = response.data.auditState;
          this.applet = response.data.applet;
          this.mpInfo = response.data.mpInfo;
          this.sign_url = response.data.auditResult.sign_url;
          this.applyment_state_msg =
            response.data.auditResult.applyment_state_msg;
          this.audit_detail = response.data.auditResult.audit_detail;
          this.$refs.mychild.getCommercial(this.CommercialData);
        });
      },
      getisBindThirdParty() {
        isBindThirdParty(this.authorizationType).then((response) => {
          this.MerchantID = response.merchantId;
          this.MerchantIDType = response.merchantId;
          this.authorizationStatus = response.authorizationStatus;
          this.authorizerAppid = response.authorizerAppid
          this.businessCode = response.businessCode
          this.isIssueStatus = response.isIssue;
          if(this.isIssueStatus == '0'){
            this.releaseStatus = true;
          }else {
            this.releaseStatus = false;
          }

          // if (this.authorizationStatus == 0) {
          //   this.getCommercial(response.businessCode);
          // }
          if (response.authorizerType == "applet") {
            if (response.authorizationStatus == 0) {
              this.nextStep = false;
            }
          }

          if(response.issueStatus == "true" || response.issueStatus == true){
            this.releaseType =  true;
          }else{
            this.releaseType =  false;
          }

          if(response.funcType == "true" || response.funcType == true){
            this.funcType = true;
          }else{
            this.funcType = false;
          }

          if(response.funcType == "true" || response.funcType == true){
            this.funcTypeStatus = true;
          }else{
            this.funcTypeStatus = false;
          }

        });
      },
      release() {
        releaseRequest(this.authorizationType).then((response) => {
          if(response =='0'){
            isBindThirdParty(this.authorizationType).then((response) => {
              this.isIssueStatus = response.isIssue;
              if(this.isIssueStatus == '0'){
                this.releaseStatus = true;
              }else {
                this.releaseStatus = false;
              }
            });
            this.msgSuccess("发布成功");
            location.reload();
          }
        });
      },
      SelectTemplate() {
        this.$router.push("/platform/template");
      },
      complete() {
        this.$router.go(0);
      },

      Next() {
        getAuditstatusRequest(this.authorizationType).then((response) => {
          this.auditstatus = response.status;

          // this.releaseType = response.isIssue;
          this.reason = response.reason;
          console.log("审核状态", this.auditstatus);
          console.log("是否自动发布", this.releaseType);
          console.log("reason", this.reason);
        });
        this.active = 2;
      },
      Next1() {
        this.active = 2;
      },
      Next3() {
        this.active = 1;
      },
      Next4() {
        this.active = 3;
      },
      //点击授权
      authorization() {
        let indexUrl = process.env.VUE_APP_BASE + "/store/applet/authorization";
        let authorizationStatus = "0";
        appletGrant(indexUrl, this.authorizationType,authorizationStatus).then((response) => {
          let url = response.data.grantUrl;
          window.location.href = url;
        });
      },
      //注册小程序
      register() {
        // this.$router.push("/register/data/");
        window.open("https://mp.weixin.qq.com/");
      },
      //修改当前授权单
      registerPlay() {
        var authorizerAppid = this.authorizerAppid
        var businessCode = this.businessCode
        this.$router.push("/payAudit/data?authorizer=" + authorizerAppid + "&businessCode=" + businessCode);
      },
      //新增授权单
      newRegisterPlay() {
        var authorizerAppid = this.authorizerAppid
        this.$router.push("/payAudit/data?authorizer=" + authorizerAppid + "&businessCode=" + null);
      },
      setPaymentTypeclick() {
        setPaymentTypeRequest(this.MerchantID, this.authorizationType).then(
          (response) => {
            if (response == 0) {
              this.msgSuccess("设置支付方式成功");
              this.MerchantID = "";
              this.nextStep1 = false;
            } else {
              this.msgError("设置支付方式失败");
              this.MerchantID = "";
              this.nextStep1 = true;
            }
            console.log("设置支付方式方式" + response);
          }
        );
      },
      submitAuditcilck() {
        const loadingObj = this.$loading({
          lock: true,
          text: '提交中....',
          spinner: 'el-icon-loading',
          background: 'rgba(0,0,0,0.7)',
          target: document.querySelector('.submit-test-dialog')
        });
        submitAuditRequest(this.releaseType, this.funcType, this.authorizationType).then(
          (response) => {
            loadingObj.close();
            console.log("提交审核返回值" + response);
            if(response == 'notFitment'){
              console.log("当前并未装修店铺")
              this.$confirm('当前并未装修店铺，是否去装修', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                   this.$router.push("/store/template");
              }).catch(() => {

              });
            }

            if(response == '86002'){
              this.msgError("小程序还未设置昵称、头像、简介。请先设置完后再重新提交");
            }

            if (response == '48001') {
              console.log("当前未开通直播权限")
              this.$confirm('当前未开通直播权限，是否开通', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                console.log("开始开通直播权限");
                applyFor().then((response) => {
                  console.log("开通直播权限返回值" + response);
                  if (response.data) {
                    this.$message({
                      type: 'success',
                      message: '开通成功'
                    });
                  }
                });
              }).catch(() => {
                console.log("取消开通直播权限");
              });
            }
            // this.release();

            getAuditstatusRequest(this.authorizationType).then((response) => {
              if (response.status != null) {
                this.auditstatus = response.status;
              }
              if (response.isIssue != null) {
                this.releaseType = response.isIssue;
              }
              if (response.reason != null) {
                this.reason = response.reason;
              }
            });

          }
        );
      },
      //查询授权单列表
      getWechatPayAuditList() {
        wechatPayAuditList("SALES_SCENES_MINI_PROGRAM").then((response) => {
          this.payData = response.data
          this.dialogVisible = true
        })
      },
      //切换授权单
      switchPay(row) {
        this.QuerySwitchPayAuditVo.authorizerAppid = this.authorizerAppid
        this.QuerySwitchPayAuditVo.businessCode = row.businessCode
        this.QuerySwitchPayAuditVo.authorizerType = "applet"
        this.QuerySwitchPayAuditVo.subMchid = row.subMchid
        console.log("切换授权单请求参数")
        switchPayAudit(this.QuerySwitchPayAuditVo).then((response) => {
          this.dialogVisible = false
        })
      }
    },
  };
</script>

<style lang="scss" scoped>
  .el-input__inner {
    text-align: center !important;
  }

  .el-button+.el-button {
    margin-left: 0;
  }

  el-input.text {
    text-align: center;
  }

  .steps {
    width: 1180px;
    height: auto;
    margin: 50px auto 0;
  }

  .bg {
    background-color: #f2f2f6;
    border-radius: 6px;
    width: 1200px;
    height: 550px;
    margin: 50px auto 0;
    padding: 10px;

    .AppletsBind {
      border-radius: 6px;
      width: 100%;
      height: 100%;
      background-color: #fff;
    }

    .AppletsBindP {
      width: 100%;
      text-align: center;
      padding: 20px 0;
      font-weight: bold;
      color: #595961;
      position: relative;
      top: 13px;
      // left: 5px;
    }

    .AppletsBindDiv {
      position: relative;
      width: 500px;
      height: 300px;
      border: 1px solid #e3e2e5;
      display: inline-block;
      margin: 30px 0 0 60px;
      border-radius: 6px;

      .AppletsBindDivLeft {
        width: 60px;
        height: 73px;
        position: absolute;
        left: 50%;
        top: 17%;
        margin-left: -30px;

        .AppletsBindDivtopImgtow {
          width: 100%;
          height: 100%;
          background-image: url("../../../assets/images/payment.png");
          background-size: 100% 100%;
        }

        .AppletsBindDivLeftImg {
          width: 60px;
          height: 73px;
          background-image: url("../../../assets/images/bindApplet.png");
          background-size: 100% 100%;
        }

        .AppletsBindDivtopImg {
          width: 150px;
          height: 150px;
          position: relative;
          top: -40px;
          left: -40px;

          img {
            width: 100%;
            height: 100%;
          }
        }

        .AppletsBindButton {
          position: relative;
          top: 20px;
          right: 75px;
          width: 186px;
          height: 40px;
        }

        .AppletsBindButtons {
          position: relative;
          top: 40px;
          right: 60px;
          width: 186px;
          height: 40px;
        }

        .AppletsBindTitle {
          position: relative;
          top: 60px;
          right: 68px;
        }

        .AppletsBindTitles {
          position: relative;
          top: 20px;
          right: 68px;
        }

        .AppletsBindDivtop {
          width: 60px;
          height: 73px;
          position: absolute;
          left: 50%;
          top: 10%;
          margin-left: -30px;

          .AppletsBindDivtopImg {
            width: 100px;
            height: 100px;
            background-image: url("../../../assets/images/payment.png");
            background-size: 100% 100%;
          }

          .AppletsBindBox {
            position: absolute;
            top: 60px;
            left: -55px;
          }

          .AppletsBindButton2 {
            width: 186px;
            height: 40px;
          }
        }
      }

      .AppletsBindDivRight {
        width: 60px;
        height: 73px;
        position: absolute;
        left: 50%;
        top: 20%;
        margin-left: -30px;

        .AppletsBindDivRightImg {
          width: 60px;
          height: 73px;
          background-image: url("../../../assets/images/appleyForApplet.png");
          background-size: 100% 100%;
        }

        .GainCommercial {
          width: 60px;
          height: 73px;
          background-image: url("../../../assets/images/gainCommercial.png");
          background-size: 100% 100%;
        }

        .AppletsBindButton {
          position: relative;
          top: 40px;
          right: 65px;
          width: 195px;
          height: 40px;
        }

        .AppletsBindTitle {
          position: relative;
          top: 60px;
          right: 68px;
        }
      }
    }

    .AppletsBindbtn {
      display: inline-block;
      margin: 35px 0 0 60px;
      width: 1060px;
      height: 80px;
      border-radius: 6px;
      border: 1px solid #e3e2e5;
      text-align: center;
      line-height: 60px;

      .AppletsBindbtnIcon {
        width: 22px;
        height: 26px;
        background-image: url("../../../assets/images/AppletsBindBottom.png");
        background-size: 100% 100%;
        display: inline-block;
        position: relative;
        top: 7px;
        right: 7px;
      }
    }

    .AppletsBindbtn1 {
      display: inline-block;
      margin: 35px 0 0 60px;
      width: 520px;
      height: 80px;
      border-radius: 6px;
      border: 1px solid #e3e2e5;
      text-align: center;
      line-height: 60px;

      .AppletsBindbtnIcon {
        width: 22px;
        height: 26px;
        background-image: url("../../../assets/images/AppletsBindBottom.png");
        background-size: 100% 100%;
        display: inline-block;
        position: relative;
        top: 7px;
        right: 7px;
      }
    }

    .AppletsBindbtn2 {
      display: inline-block;
      margin: 35px 0 0 20px;
      width: 520px;
      height: 80px;
      border-radius: 6px;
      border: 1px solid #e3e2e5;
      text-align: center;
      line-height: 60px;

      .AppletsBindbtnIcon {
        width: 22px;
        height: 26px;
        background-image: url("../../../assets/images/AppletsBindBottom.png");
        background-size: 100% 100%;
        display: inline-block;
        position: relative;
        top: 7px;
        right: 7px;
      }
    }

    .AppletsBindbtnS {
      margin-top: 35px;
    }

    .AppletsBindbtn3 {
      display: inline-block;
      margin: 0 20px 0 0;
      width: 520px;
      height: 80px;
      border-radius: 6px;
      border: 1px solid #e3e2e5;
      text-align: center;
      line-height: 60px;

      .AppletsBindbtnIcon {
        width: 22px;
        height: 26px;
        background-image: url("../../../assets/images/AppletsBindBottom.png");
        background-size: 100% 100%;
        display: inline-block;
        position: relative;
        top: 7px;
        right: 7px;
      }
    }

    .AppletsBindbtn4 {
      display: inline-block;
      width: 520px;
      height: 80px;
      border-radius: 6px;
      border: 1px solid #e3e2e5;
      text-align: center;
      line-height: 60px;

      .AppletsBindbtnIcon {
        width: 22px;
        height: 26px;
        background-image: url("../../../assets/images/AppletsBindBottom.png");
        background-size: 100% 100%;
        display: inline-block;
        position: relative;
        top: 7px;
        right: 7px;
      }
    }

    .AppletsBindDiv2 {
      position: relative;
      width: 500px;
      height: 300px;
      border: 1px solid #e3e2e5;
      left: 50%;
      top: 30px;
      margin-left: -250px;
      border-radius: 6px;

      .AppletsBindDivtop {
        width: 60px;
        height: 73px;
        position: absolute;
        left: 50%;
        top: 20%;
        margin-left: -30px;

        .AppletsBindDivtopImgtow {
          width: 100%;
          height: 100%;
          background-image: url("../../../assets/images/payment.png");
          background-size: 100% 100%;
        }

        .AppletsBindDivtopImg {
          width: 150px;
          height: 150px;
          position: relative;
          top: -40px;
          left: -40px;

          img {
            width: 100%;
            height: 100%;
          }
        }

        .AppletsBindBox {
          position: absolute;
          top: 60px;
          left: -55px;
        }

        .AppletsBindButton2 {
          // position: absolute;
          //   bottom:20px;
          //   left: 150px;
          width: 186px;
          height: 40px;
        }
      }
    }

    .AppletsBindDiv3 {
      position: relative;
      width: 500px;
      height: 300px;
      border: 1px solid #e3e2e5;
      left: 50%;
      top: 30px;
      margin-left: -250px;
      border-radius: 6px;

      .AppletsBindDivRelease {
        width: 60px;
        height: 73px;
        position: absolute;
        left: 50%;
        top: 20%;
        margin-left: -30px;

        .AppletsBindDivReleaseImg {
          width: 60px;
          height: 73px;
          background-image: url("../../../assets/images/auditApplet.png");
          background-size: 100% 100%;
        }

        .AppletsBindBox {
          position: absolute;
          top: 60px;
          left: -55px;
        }

        .AppletsBindButton2 {
          // position: absolute;
          //   bottom:20px;
          //   left: 150px;
          width: 186px;
          height: 40px;
        }
      }
      .erroeAppletsBindDivRelease {
        width: 60px;
        height: 73px;
        position: absolute;
        left: 50%;
        top: 1%;
        margin-left: -30px;

        .AppletsBindDivReleaseImg {
          width: 60px;
          height: 73px;
          background-image: url("../../../assets/images/auditApplet.png");
          background-size: 100% 100%;
        }

        .AppletsBindBox {
          position: absolute;
          top: 60px;
          left: -55px;
        }

        .AppletsBindButton2 {
          // position: absolute;
          //   bottom:20px;
          //   left: 150px;
          width: 186px;
          height: 40px;
        }
      }


    }
  }
</style>
